<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 19] 19.3 java.awt.datatransfer.DataFlavor (JDK 1.1)</TITLE>
<META NAME="author" CONTENT="David Flanagan">
<META NAME="date" CONTENT="Thu Jul 31 16:12:11 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java">
<META NAME="title" CONTENT="Java in a Nutshell">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java in a Nutshell" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch19_02.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 19<br>The java.awt.datatransfer Package</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch19_04.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JNUT2-CH-19-SECT-3">19.3 java.awt.datatransfer.DataFlavor (JDK 1.1)</A></h2>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-19-SECT-3.1"></A></h3>
</DIV>

<P CLASS=para>
Objects of this type define a data type or format for the
purposes of data transfer.  A <tt CLASS=literal>DataFlavor</tt> is
characterized by two values.  The first is a descriptive
human-readable name, passed to a <tt CLASS=literal>DataFlavor()</tt>
constructor or set with <tt CLASS=literal>setHumanPresentableName()</tt>.

<P CLASS=para>
The second component of a <tt CLASS=literal>DataFlavor</tt> specifies the
type of data to be transferred in a more machine-readable
way.  The two <tt CLASS=literal>DataFlavor()</tt> constructors allow two
distinct ways to specify this data type.  One way is by
directly specifying the representation class of the data.
This is a <tt CLASS=literal>Class</tt> object that defines the Java type
that the recipient of a data transfer is passed.  The
other way to specify the data type represented by a
<tt CLASS=literal>DataFlavor</tt> is to pass a string that specifies the
MIME type of the data to be transferred.

<P CLASS=para>
When you construct a <tt CLASS=literal>DataFlavor</tt> object by specifying
the representation type of the data, the MIME type of the
<tt CLASS=literal>DataFlavor</tt> is automatically set to:

<DIV CLASS=screen>
<P>
<PRE>
application/x-java-serialized-object class=<tt CLASS=literal>classname</tt>
</PRE>
</DIV>

<P CLASS=para>
This indicates that
the object is to be transferred using the data format of the
Java object serialization protocol.  When you pass a MIME type
string to the <tt CLASS=literal>DataFlavor()</tt> constructor, on the other
hand, the representation class of the <tt CLASS=literal>DataFlavor</tt>
is automatically set to the <tt CLASS=literal>Class</tt> object for
<tt CLASS=literal>java.io.InputStream</tt>.  This means that the recipient
of the data transfer is given an <tt CLASS=literal>InputStream</tt>
object from which it can read and parse data in the
specified MIME format.

<P CLASS=para>
Because the same MIME type can be specified with a number of
slightly different strings, the <tt CLASS=literal>DataFlavor</tt> class
converts the MIME type to a canonical form so that it can
be uniquely identified and compared.  Use
<tt CLASS=literal>isMimeTypeEqual()</tt> to compare the MIME type of a
<tt CLASS=literal>DataFlavor</tt> object with another MIME type, or with
the MIME type of another <tt CLASS=literal>DataFlavor</tt>.

<P CLASS=para>
Because textual data is so often transferred, the
<tt CLASS=literal>DataFlavor</tt> class defines constants for two
commonly-used data flavors.  <tt CLASS=literal>stringFlavor</tt> represents
text transferred as a <tt CLASS=literal>String</tt> object, while
<tt CLASS=literal>plainTextFlavor</tt> represents text transferred through
an <tt CLASS=literal>InputStream</tt>, using the <tt CLASS=literal>text/plain</tt> MIME type.

<DIV CLASS=screen>
<P>
<PRE>
public class <tt CLASS=literal>DataFlavor</tt> extends Object {
    // <tt CLASS=literal>Public Constructors</tt>
            public <tt CLASS=literal>DataFlavor</tt>(Class <tt CLASS=literal>representationClass</tt>, String <tt CLASS=literal>humanPresentableName</tt>);
            public <tt CLASS=literal>DataFlavor</tt>(String <tt CLASS=literal>mimeType</tt>, String <tt CLASS=literal>humanPresentableName</tt>);
    // <tt CLASS=literal>Class Variables</tt>
            public static DataFlavor <tt CLASS=literal>plainTextFlavor</tt>;
            public static DataFlavor <tt CLASS=literal>stringFlavor</tt>;
    // <tt CLASS=literal>Public Instance Methods</tt>
            public boolean <tt CLASS=literal>equals</tt>(DataFlavor <tt CLASS=literal>dataFlavor</tt>);
            public String <tt CLASS=literal>getHumanPresentableName</tt>();
            public String <tt CLASS=literal>getMimeType</tt>();
            public Class <tt CLASS=literal>getRepresentationClass</tt>();
            public boolean <tt CLASS=literal>isMimeTypeEqual</tt>(String <tt CLASS=literal>mimeType</tt>);
            public final boolean <tt CLASS=literal>isMimeTypeEqual</tt>(DataFlavor <tt CLASS=literal>dataFlavor</tt>);
            public void <tt CLASS=literal>setHumanPresentableName</tt>(String <tt CLASS=literal>humanPresentableName</tt>);
    // <tt CLASS=literal>Protected Instance Methods</tt>
            protected String <tt CLASS=literal>normalizeMimeType</tt>(String <tt CLASS=literal>mimeType</tt>);
            protected String <tt CLASS=literal>normalizeMimeTypeParameter</tt>(String <tt CLASS=literal>parameterName</tt>, String <tt CLASS=literal>parameterValue</tt>);
}
</PRE>
</DIV>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-19-SECT-3.2">Passed To:</A></h3>

<P CLASS=para>
<tt CLASS=literal>DataFlavor.equals(), 
DataFlavor.isMimeTypeEqual(), 
StringSelection.getTransferData(), 
StringSelection.isDataFlavorSupported(), 
Transferable.getTransferData(), 
Transferable.isDataFlavorSupported(), 
UnsupportedFlavorException()</tt>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-19-SECT-3.3">Returned By:</A></h3>

<P CLASS=para>
<tt CLASS=literal>StringSelection.getTransferDataFlavors(), 
Transferable.getTransferDataFlavors()</tt>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-19-SECT-3.4">Type Of:</A></h3>

<P CLASS=para>
<tt CLASS=literal>DataFlavor.plainTextFlavor, 
DataFlavor.stringFlavor</tt>

</DIV>

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch19_02.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch19_04.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>java.awt.datatransfer.ClipboardOwner (JDK 1.1)</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>java.awt.datatransfer.StringSelection (JDK 1.1)</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
